<template>
  <div class="station">
    <el-table :data="stationStore.stationList" style="width: 100%">
      <el-table-column fixed prop="key" label="Id" width="300" />
      <el-table-column prop="station" label="车站" width="300">
        <template #default="{ row }">
          {{ select(row.station) }}
        </template>
      </el-table-column>
      <el-table-column props="state" label="状态" width="300">
        <template #default="{ row }">
          <el-switch v-model="row.state" class="ml-2" width="60" inline-prompt active-text="启用" inactive-text="停用" />
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="操作" width="300">
        <template #default="{ row }">
          <img style="width: 30px; height: 30px;" src="../../../public/img/png/编辑.png" alt="" @click="edit(row)">
          <img style="width: 30px; height: 30px;" src="../../../public/img/png/Del.png" alt="" @click="del(row)" />
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script setup lang="ts">
import { onMounted } from "vue";
import * as api from '@/api'
import { useStationStore } from '@/stores/counter'
const stationStore = useStationStore()

onMounted(() => {
  api.StationList(stationStore)
  console.log(stationStore)
})

const select = (city: string) => {
  if (city.slice(-1) === '市' || city.slice(-1) === '县') {
    return city.slice(0, -1) + '站'
  } else {
    return city
  }
}

const edit = (row: any) => {

}

const del = (row: any) => {
  stationStore.delStationList(row.key)
}
</script>

<style></style>